package fileNoeud;

import arbre.Element;
import arbre.Noeud;
import arbre.NoeudFeuille;
import java.util.Iterator;
import java.util.LinkedHashMap;

public class FilePrioriteeDeNoeud {

    private ListePrioriteeDeNoeud maliste;

    public FilePrioriteeDeNoeud() {
        maliste = new ListePrioriteeDeNoeud();
    }

    public boolean estVide() {
        return maliste.estVide();
    }

    public void insererPrioritee(Noeud noeud) {
        maliste.insererPrioritee(noeud);
    }

    public Noeud depiler() throws NoSuchElementException {
        if (estVide()) {
            throw new NoSuchElementException();
        }

        return maliste.supprimerTete();
    }

    public void construireFilePrioritee(LinkedHashMap dictionnaireFrequences) {

        Character key;
        Iterator i = dictionnaireFrequences.keySet().iterator();

        while (i.hasNext())
        {
            key = (Character)i.next();
            insererPrioritee(new NoeudFeuille(new Element<Character>(key, (Integer)dictionnaireFrequences.get(key))));
        }

        System.out.println(toString());
        
    }


    @Override
    public String toString() {
        return "ma file : " + maliste.toString();
    }
}
